package cn.lili.modules.serviceimpl;

import cn.lili.modules.entity.AppVideosView;
import cn.lili.modules.mapper.AppVideosViewMapper;
import cn.lili.modules.service.AppVideosViewService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author:xiangqian
 * @date: 2024/3/8 20:30
 */
@Service
public class AppVideosViewServiceImpl extends ServiceImpl<AppVideosViewMapper, AppVideosView> implements AppVideosViewService {

    /**
     * 根据openid查询浏览过的视频ID
     *
     * @param openId
     * @return 多个浏览过的视频ID
     */
    @Override
    public List<Integer> getVideoIdsByOpenId(String openId) {
        LambdaQueryWrapper<AppVideosView> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(AppVideosView::getVideo_id);
        queryWrapper.eq(AppVideosView::getUser_id, openId);
        List<AppVideosView> appVideosViews = this.baseMapper.selectList(queryWrapper);

        return appVideosViews.stream()
                .map(AppVideosView::getVideo_id)
                .collect(Collectors.toList());
    }
}
